﻿@{
    ViewBag.Title = "设备类型管理";
}
@using FMS.UI.Extension;
@section headSecion{
    <script type="text/javascript">
        $(function() {
            $.globalHelper.datagridPara.init("/Factory/Factory_Machines_Kind/KindIndex", [@Html.GetSonBtnJs()], [
                [
                    { field: 'factory_Machines_Kind_Name', title: '设备类型名称', width: 100 },
                    { field: 'factory_Machines_Kind_Number', title: '设备类型编码', width: 100 }
                ]
            ]);
            $("#tbList").datagrid($.globalHelper.datagridPara.paras);
            //分类选择
            searchJS();
            kindOne($('#kind0'), "/Factory/Factory_Machines_Kind/Kind0sel");
            $("#kind0").change(kindOnechange);
            $("#kind1").change(kindTwochange);
            $("#kind2").change(kindThreechange);
            });
        @if (Html.IsBtnExist("add"))
        {
            <text>

        function add() {
            $.globalHelper.showCommonWindow("新增设备类型", "/Factory/Factory_Machines_Kind/KindAdd", 380, 140);
        }
        </text>
        }
        @if (Html.IsBtnExist("remove"))
        {
            <text>
        function remove() //设置用户所属角色
        {

            ifSelected(function(selectedRowData) {
                window.top.ComSkipMsg(selectedRowData, "/Factory/Factory_Machines_Kind/KindDel");
            });
        }
        </text>
        }
        @if (Html.IsBtnExist("modify"))
        {
            <text>
        function modify() {

            ifSelected(function(selectedRowData) {
                $.globalHelper.showCommonWindow("修改使用状态", "/Factory/Factory_Machines_Kind/KindModify/" + selectedRowData.factory_Machines_Type_Id, 380, 140);
            });
        }
        </text>
        }

        //统一判断是否有选中行 有则调用回掉函数(func) 并存入选中行的数据
        function ifSelected(func) //func回调函数 去执行操作
        {
            //获取选中行数据
            var selectedRowData = $("#tbList").datagrid("getSelected");
            if (selectedRowData) {
                if (func && func instanceof Function) {
                    $.ajax({
                        url: "/Factory/Factory_Machines_Kind/KindCheck",
                        type: "post",
                        data: { ss: selectedRowData.UID },
                        success: function(da) {
                            if (da == 1) {
                                $.msgBoxObj.showInfo("用户名不存在");
                                $.globalHelper.reloadSeletecTabDataGrid();
                            } else {
                                func(selectedRowData); //调用回调函数，并传入 选中行的数据
                            }
                        },
                        async: true
                    });
                }
            } else {
                $.msgBoxObj.showInfo("请选中要操作的行");
            }

        };

        function kindItem() {
            var selectKind = function (sel, url) {
                sel.empty();
                $.post(url, function (data) {
                    sel.append("<option value='-1'>请选择一级分类</optin>");
                    $.each(data, function (name, value) {
                        sel.append("<option value=" + value.id + ">" + value.k0name + "</optin>");
                    });
                });

            };

            selectKind($('#kind0'), "/Factory/Factory_Machines_Kind/Kind0sel");
        }

        function searchJS() {
            return $("<table id=tbHead><tr><td style='padding:0 8px'><label>请选择一级分类:</label></td><td><select id=kind0></select></td><td style='padding:0 8px'><label>请选择二级分类:</label></td><td><select id=kind1></select></td><td style='padding:0 8px'><label>请选择三级分类:</label></td><td><select id=kind2></select></td></tr></table>").appendTo($('.datagrid-toolbar'));

        };

        
            function kindOne(sel, url) {
                sel.empty();
                $.post(url, function(data) {
                    sel.append("<option value='-1'>请选择一级分类</optin>");
                    $.each(data, function(name, value) {
                        sel.append("<option value=" + value.id + ">" + value.k0name + "</optin>");
                    });
                });

            };
            function kindOnechange() {
                var sel = $("#kind1");
                sel.empty();
                var id = this.value;
                $.post("/Factory/Factory_Machines_Kind/Kind1sel", { "id": id }, function(data) {
                    sel.append("<option value='-1'>请选择二级分类</optin>");
                    $.each(data, function(name, value) {
                        sel.append("<option value=" + value.id + ">" + value.k1name + "</optin>");
                    });
                });


            }
            function kindTwochange() {
                var sel = $("#kind2");
                sel.empty();
                var id = this.value;
                $.post("/Factory/Factory_Machines_Kind/Kind2sel", { "id": id }, function(data) {
                    sel.append("<option value='-1'>请选择三级分类</optin>");
                    $.each(data, function(name, value) {
                        sel.append("<option value=" + value.id + ">" + value.k2name + "</optin>");
                    });
                });
            }
                function kindThreechange() {
                    var id = this.value;
                    $.globalHelper.datagridPara.init("/Factory/Factory_Machines_Kind/Kind?id=" + id, [@Html.GetSonBtnJs()], [
                        [
                            { field: 'factory_Machines_Kind_Name', title: '设备类型名称', width: 100 },
                            { field: 'factory_Machines_Kind_Number', title: '设备类型编码', width: 100 }
                        ]
                    ]);
                
                 $("#tbList").datagrid($.globalHelper.datagridPara.paras);
                    searchJS();
                    kindOne($('#kind0'), "/Factory/Factory_Machines_Kind/Kind0sel");
                    $("#kind0").change(kindOnechange);
                    $("#kind1").change(kindTwochange);
                    $("#kind2").change(kindThreechange);
                }
       
    </script>
}

<table id="tbList" style="width: 100%;height:100%"></table>

